<div class="modal fade" id="modalInscription" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title" id="myModalLabel">Modal title</h4>
			</div>
			<div class="modal-body">
				Confirmez l'inscription à la formation n° <span id="txtNumero"> </span> 
				<span style="color: red; font-weight: bold" id="txtLibelle"> </span> 
				de niveau <span style="color: green; font-weight: bold" id="txtNiveau"> </span> 
				le <span style="color: blue; font-weight: bold" id="txtDate"> </span> ?
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Annuler</button>
				<button type="button" class="btn btn-primary" onClick="confirmationInscription()">Confirmer</button>
			</div>
		</div>
	</div>
</div>


<div class="container contenu">
	
	<?php
		$rows = $enregt->result_array();
		if (!empty($rows))
		{
			echo "<span id='titre'>Liste des sessions de formation disponible</span>";
			echo "<table class='table table-bordered'>";
			echo "
			<tr>
			<th>Numero</th>
			<th>Libelle formation</th>
			<th>Niveau de la formation</th>
			<th>Date Début</th><th>nombre de places</th>
			<th>Nombre d'inscrits</th>
			<th colspan='2'>Option</td>
			</tr>";
			foreach ($rows as $ligne)
			{
			echo "<tr>";
			echo "<td>" . $ligne['numero'] . "</td>";
			echo "<td>" . $ligne['libelleform'] . "</td>";
			echo "<td>" . $ligne['niveauform'] . "</td>";
			echo "<td>" . $ligne['datedebut'] . "</td>";
			echo "<td>" . $ligne['nb_places'] . "</td>";
			echo "<td>" . $ligne['nb_inscrits'] . "</td>";
			echo '<td> <button class="btn btn-default" data-toggle="modal" data-target="#modalInscription" data-niveau='.$ligne["niveauform"].' data-libelle='.$ligne["libelleform"].' data-numero='.$ligne["numero"].' data-date='.$ligne["datedebut"].' > Inscription </button></td>';
			}
			

			if (count($rows) > 4) {
				echo "<tr><td colspan='8'>";
				echo $this->pagination->create_links();
				echo "</td>";
				echo "</tr>";
			}
			 //Creation des liens pour passer de page en page
					
				
			echo "</table>";
		}
		else
		{
			echo "<h1><u> AUCUNE SESSION DISPONIBLE </u></h1>";
			echo "Redirection dans 5 secondes ...";
			?>

			<!-- Button trigger modal -->


			<script>
				var redirect = function() {

    				window.location.href = "<?php echo site_url('/accueil/index'); ?>";
				};

				setTimeout(redirect, 5000);
			</script>

			<?php
		}
		

	?>

	<script>
	var numSesion;
	var libelleSession;
	var niveauSession;
		function confirmationInscription()
		{
			window.location.href = "<?php echo site_url('/gestionSessionClient/inscription/" + numSession + "/" + libelleSession + "/" + niveauSession + "'); ?>";	
		};

		$('#modalInscription').on('show.bs.modal', function (event) {
  			var button = $(event.relatedTarget)
  			var niveau = button.data('niveau');
  			var libelle = button.data('libelle');
  			var numero = button.data('numero');
  			var date = button.data('date');

  			var modal = $(this)
  			modal.find('.modal-title').text('Inscription à ' + libelle + ' ( ' + niveau + ' )')
  			modal.find('#txtLibelle').text(libelle);
  			modal.find('#txtNiveau').text(niveau);
  			modal.find('#txtNumero').text(numero);
  			modal.find('#txtDate').text(date);

  			numSession = numero;
  			libelleSession = libelle;
  			niveauSession = niveau;
		});
  	</script>
		
</div>